在k8s中使用mc作为initContainer,结果发现失败时报错比较模糊,不知如何排查。
排查过程执行两个命令,报错mc: Unable to prepare URL for copying. Unable to guess the type of copy operation.命令1:
mc alias set myminio $MINIO_ENDPOINT $MINIO_ACCESS_KEY $MINIO_SECRET_KEYmc cp --recursive myminio/ /# mc: Unable to prepare URL for copying. Unable to guess the type of copy operation.发现 MINIO_ACCESS_KEY 和 MINIO_SECRET_KEY是空的,导致下载的时候报错。将两个变量更正后恢复正常。
命令2:
mc cp --recursive / myminio/# mc: Unable to prepare URL for copying. Unable to guess the type of copy operation.最后发现问题是/ 目录不存在。如果用早期版本的mc 会报出mc: Unable to validate source /: Object does not exist.
解决方案建议上传时,检查本地路径是否存在;下载时,检查远程bucket是否存在、endpoint是否正确。如果不能找出原因,尝试使用mc --debug 进行cp/mv/ls等操作。尝试使用旧版本的mc(RELEASE.2023-10-04T06-52-56Z或更早版本)进行操作,可能会给出更清晰的错误信息。关于mc版本错误信息的改动是在 minio/mc#4710 引入的。受影响的版本从RELEASE.2023-10-14T01-57-03Z开始。这个改动是为了减少cp/mv的延时,但是个人感觉这个改动却带来了调试上的麻烦。
Github上有一个关于这个错误信息问题的Issue,目前测试一直到RELEASE.2024-05-09T17-04-24Z版本都还未修正。
模糊报错:
$ docker run -it --rm minio/mc:RELEASE.2023-10-14T01-57-03Z cp -r /foo/ myio/bar mc: Configuration written to `/root/.mc/config.json`. Please update your access credentials.mc: Successfully created `/root/.mc/share`.mc: Initialized share uploads `/root/.mc/share/uploads.json` file.mc: Initialized share downloads `/root/.mc/share/downloads.json` file.mc: Unable to prepare URL for copying. Unable to guess the type of copy operation.正常报错:
$ docker run -it --rm minio/mc:RELEASE.2023-10-04T06-52-56Z cp -r /foo/ myio/barmc: Configuration written to `/root/.mc/config.json`. Please update your access credentials.mc: Successfully created `/root/.mc/share`.mc: Initialized share uploads `/root/.mc/share/uploads.json` file.mc: Initialized share downloads `/root/.mc/share/downloads.json` file.mc: Unable to validate source `/foo/`: Object does not exist参考资料https://github.com/minio/mc/issues/4893https://github.com/minio/mc/pull/4710关键词MinIO mc "Unable to prepare URL for copying"